import { Application } from 'egg';
import { createRule } from '../validate/api/index';



/**
 * 公共的路由
 */
export default (app: Application) => {
  const { auth } = app.middleware;
  const { jwt } = app;

  return {
    'upload.file': {
      method: 'POST',
      path: '/api/common/upload',
      options: {
        tags: [ 'file/upload' ],
        description: '文件上传',
        handler: app.controller.api.file.upload,
        middlewares: [ jwt, auth('common.upload') ],
      },
    },
    'common.aiText': {
      method: 'POST',
      path: '/api/baidu/aiText',
      options: {
        tags: ['baidu/ai'],
        description: '百度ai文本请求',
        handler: app.controller.api.ai.aiText,
        middlewares: [jwt, auth('common.aiText')],
        validate: createRule,
      },
    },
    'common.home': {
      method: 'GET',
      path: '/api/mini/home',
      options: {
        tags: ['mini/home'],
        description: 'AI云链首页',
        handler: app.controller.xxm.home.index,
        middlewares: [jwt, auth('common.home')],
        validate: createRule,
      },
    }
  };
};
